home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / boot_up / bmpshow2 / graphics.c < prev    next >
C/C++ Source or Header  |  1995-04-27  |  37KB  |  1,482 lines

  1. #include <stdio.h>
  2. #include <tos.h>
  3.  
  4. #define G_REPLACE 1
  5. #define G_AND     2
  6. #define G_XOR     3
  7. #define G_NOT     4
  8. #define G_OR      5
  9.  
  10. typedef struct
  11. {
  12.    unsigned int red:5;
  13.    unsigned int green:5;
  14.    unsigned int overlay:1;
  15.    unsigned int blue:5;
  16. }HIGHCOLOR;
  17.  
  18. int color_shift;
  19. int _ybase, _xbase;
  20. int _circle_color;
  21. int _max_x, _max_y;
  22. unsigned long _aspect;
  23. float _monitor_aspect = 0.75;  /* Aspect ratio of your monitor. */
  24. long *_ytable;
  25. long *_scale;
  26. long *_scaleptr;
  27. int _write_mode = G_REPLACE;
  28.  
  29. /* ------------------------------------------------------------------- */
  30. /*    Function Prototype                                               */
  31. /* ------------------------------------------------------------------- */
  32.  
  33. int (*p_pixel)(int x, int y, int color);
  34. int (*g_pixel)(int x, int y);
  35. int (*d_line)(int x1, int y1, int x2, int y2, int color);
  36. int (*d_hline)(int x1, int x2, int y, int color);
  37. int (*byte2raw)(char *colors, char *buffer);
  38.  
  39. int pinit(int max_x, int max_y, void *video_buffer, int planes);
  40. void pexit(void);
  41.  
  42. int set_pixel1(int x, int y, int color);
  43. int set_pixel2(int x, int y, int color);
  44. int set_pixel4(int x, int y, int color);
  45. int set_pixel8(int x, int y, int color);
  46. int set_pixel16(int x, int y, int color);
  47.  
  48. int get_pixel1(int x, int y);
  49. int get_pixel2(int x, int y);
  50. int get_pixel4(int x, int y);
  51. int get_pixel8(int x, int y);
  52. int get_pixel16(int x, int y);
  53.  
  54. extern int byte2raw8(char *color, char *buffer);
  55. extern int byte2raw4(char *color, char *buffer);
  56. extern int byte2raw2(char *color, char *buffer);
  57. extern int byte2raw1(char *color, char *buffer);
  58.  
  59. void draw_line1(int x1, int y1, int x2, int y2, int color);
  60. void draw_line2(int x1, int y1, int x2, int y2, int color);
  61. void draw_line4(int x1, int y1, int x2, int y2, int color);
  62. void draw_line8(int x1, int y1, int x2, int y2, int color);
  63. void draw_line16(int x1, int y1, int x2, int y2, int color);
  64. void draw_hline1(int x1, int x2, int y, int color);
  65. void draw_hline2(int x1, int x2, int y, int color);
  66. void draw_hline4(int x1, int x2, int y, int color);
  67. void draw_hline8(int x1, int x2, int y, int color);
  68. void draw_hline16(int x1, int x2, int y, int color);
  69.  
  70. void set_colors(void);
  71. void set_writemode(int mode);
  72.  
  73. void _plot8(int x, int y);
  74. void _plot(int x, int y);
  75. void _plotfill(int x1, int x2, int y);
  76. void circle(int x, int y, int radius, int color);
  77. void disk(int x, int y, int radius, int color);
  78.  
  79. /****************************************************************/
  80. /* Set the write mode for graphics operations.                  */
  81. /****************************************************************/
  82. void set_writemode(int mode)
  83. {
  84.    switch(mode)
  85.    {
  86.       case G_REPLACE:
  87.       case G_AND:
  88.       case G_XOR:
  89.       case G_NOT:
  90.       case G_OR:      _write_mode = mode;
  91.                       break;
  92.       
  93.       default:        _write_mode = G_REPLACE;
  94.                       break;
  95.    }
  96. }
  97.  
  98. /****************************************************************/
  99. /* Draw a circle at x,y,radius,color                            */
  100. /****************************************************************/
  101. void circle(int x, int y, int radius, int color)
  102. {
  103.    register int xx, yy, sum, sx, sy;
  104.  
  105.    _xbase = x;
  106.    _ybase = y;
  107.    _circle_color = color;
  108.       
  109.    xx = 0;
  110.    yy = radius << 1;
  111.    sum = 0;
  112.    
  113.    while(xx-1 <= yy) {
  114.       if(!(xx & 1))
  115.       {
  116.          sx = xx >> 1;
  117.          sy = (yy+1) >> 1;
  118.          
  119.          _plot(sx, sy);
  120.          _plot(-sx, sy);
  121.          _plot(sx,-sy);
  122.          _plot(-sx, -sy);
  123.          
  124.          _plot(sy, sx);
  125.          _plot(-sy, sx);
  126.          _plot(sy, -sx);
  127.          _plot(-sy, -sx);
  128.       }
  129.       sum += (xx << 1) + 1;
  130.       xx++;
  131.       if(sum > 0) {
  132.          sum -= (yy << 1) - 1;
  133.          yy--;
  134.       }
  135.    }
  136. }
  137. /****************************************************************/
  138. /* Draw a disk at x,y,radius,color                              */
  139. /****************************************************************/
  140. void disk(int x, int y, int radius, int color)
  141. {
  142.    register int xx, yy, sum, sx, sy;
  143.  
  144.    _xbase = x;
  145.    _ybase = y;
  146.    _circle_color = color;
  147.       
  148.    xx = 0;
  149.    yy = radius << 1;
  150.    sum = 0;
  151.    
  152.    while(xx-1 <= yy) {
  153.       if(!(xx & 1))
  154.       {
  155.          sx = xx >> 1;
  156.          sy = (yy+1) >> 1;
  157.  
  158.          _plotfill(sx, -sx,  sy);
  159.          _plotfill(sx, -sx, -sy);
  160.          _plotfill(sy, -sy,  sx);
  161.          _plotfill(sy, -sy, -sx);
  162.       }
  163.       sum += (xx << 1) + 1;
  164.       xx++;
  165.       if(sum > 0) {
  166.          sum -= (yy << 1) - 1;
  167.          yy--;
  168.       }
  169.    }
  170. }
  171.  
  172. /****************************************************************/
  173. /* Plot each circle pixel.                                      */
  174. /****************************************************************/
  175. void _plotfill(int x1, int x2, int y)
  176. {
  177.    register int x1_pos, x2_pos, y_pos;
  178.  
  179.    if(_aspect == 0) {
  180.       x1_pos = x1 + _xbase;
  181.       x2_pos = x2 + _xbase;
  182.       y_pos  =  y + _ybase;
  183.    }
  184.    else {
  185.       x1_pos = _scale[x1] + _xbase;
  186.       x2_pos = _scale[x2] + _xbase;
  187.       y_pos = y + _ybase;
  188.    }
  189.             
  190.    if((x1_pos < 0) && (x2_pos < 0)) return;
  191.    if((x1_pos > _max_x) && (x2_pos > _max_x)) return;
  192.    if(y_pos < 0) return;
  193.    if(y_pos > _max_y) return;
  194.    
  195.    if(x1_pos < 0) x1_pos = 0;
  196.    if(x1_pos > _max_x) x1_pos = _max_x;
  197.    
  198.    if(x2_pos < 0) x2_pos = 0;
  199.    if(x2_pos > _max_x) x2_pos = _max_x;
  200.          
  201.    (*d_hline)(x1_pos, x2_pos, y_pos, _circle_color);
  202. }
  203.  
  204. /****************************************************************/
  205. /* Plot each circle pixel.                                      */
  206. /****************************************************************/
  207. void _plot(register int x, register int y)
  208. {
  209.    register int x_pos, y_pos;
  210.  
  211.    if(_aspect == 0) {
  212.       x_pos = x + _xbase;
  213.       y_pos = y + _ybase;
  214.    }
  215.    else {
  216.       x_pos = _scale[x] + _xbase;
  217.       y_pos = y + _ybase;
  218.    }
  219.    
  220.    if(x_pos < 0) return;         
  221.    if(y_pos < 0) return;
  222.    if(x_pos > _max_x) return;
  223.    if(y_pos > _max_y) return;
  224.  
  225.    (*p_pixel)(x_pos, y_pos, _circle_color);
  226. }
  227.  
  228. /****************************************************************/
  229. /* Draw a line x1,y1,x2,y2,color                                */
  230. /****************************************************************/
  231. void draw_hline1(int x1, int x2, int y, int color)
  232. {
  233.    register char *video_buffer;
  234.    register char *end_line;
  235.    register char on_mask;
  236.    register char off_mask;
  237.    register int  index;
  238.    register int  b_index;
  239.    
  240.    if(x1 < 0) x1 = 0;
  241.    if(x1 > _max_x) x1 = _max_x;
  242.    
  243.    if(x2 < 0) x2 = 0;
  244.    if(x2 > _max_x) x2 = _max_x;
  245.    
  246.    if(y > _max_y)   y = _max_y;
  247.    if(y < 0)   y = 0;
  248.       
  249.    if(x1 > x2) {
  250.       b_index = x1;
  251.       x1 = x2;
  252.       x2 = b_index;
  253.    }
  254.    
  255.    b_index = (x2 >> 3) - (x1 >> 3) - 1;
  256.    
  257.    if(b_index < 1) {
  258.       (*d_line)(x1, y, x2, y, color);
  259.       return;
  260.    }
  261.    
  262.    video_buffer = (char *)(_ytable[y] + (x1 >> 3));
  263.    on_mask = 0xff;
  264.    on_mask >>= (x1 & 0x7);
  265.    off_mask = ~on_mask;
  266.  
  267.    *video_buffer &= off_mask;
  268.    if(color & 0x1)
  269.       *video_buffer |= on_mask;
  270.  
  271.    end_line = (char *)(_ytable[y] + (x2 >> 3));
  272.    on_mask = 0xff;
  273.    on_mask >>= (x2 & 0x7);
  274.    off_mask = ~on_mask;
  275.  
  276.    *end_line &= on_mask;
  277.    if(color & 0x1)
  278.       *end_line |= off_mask;
  279.  
  280.    on_mask = 0xff;
  281.    off_mask = ~on_mask;
  282.    
  283.    for(index = 0; index < b_index; index++) {
  284.       video_buffer++;
  285.       *video_buffer &= off_mask;
  286.       if(color & 0x1)
  287.          *video_buffer |= on_mask;
  288.       
  289.    }
  290. }
  291.  
  292. /****************************************************************/
  293. /* Draw a line x1,y1,x2,y2,color                                */
  294. /****************************************************************/
  295. void draw_hline2(int x1, int x2, int y, int color)
  296. {
  297.    register int *video_buffer;
  298.    register int *end_line;
  299.    register int on_mask;
  300.    register int off_mask;
  301.    register long loff_mask;
  302.    register int index;
  303.    register int b_index;
  304.    
  305.    if(x1 < 0) x1 = 0;
  306.    if(x1 > _max_x) x1 = _max_x;
  307.    
  308.    if(x2 < 0) x2 = 0;
  309.    if(x2 > _max_x) x2 = _max_x;
  310.    
  311.    if(y > _max_y)   y = _max_y;
  312.    if(y < 0)   y = 0;
  313.       
  314.    if(x1 > x2) {
  315.       b_index = x1;
  316.       x1 = x2;
  317.       x2 = b_index;
  318.    }
  319.  
  320.    b_index = (x2 >> 4) - (x1 >> 4) - 1;
  321.    if(b_index < 1) {
  322.       (*d_line)(x1, y, x2, y, color);
  323.       return;
  324.    }
  325.    
  326.    video_buffer = (int *)((int *)_ytable[y] + ((x1 >> 3) & 0xfffe));
  327.  
  328.    on_mask = 0xFFFF >> (x1 & 0xf);
  329.    off_mask = ~on_mask;
  330.    
  331.    *(video_buffer)   &= (int) off_mask;
  332.    *(video_buffer+1) &= (int) off_mask;
  333.    
  334.    if(color & 0x1)
  335.       *video_buffer |= on_mask;
  336.  
  337.    if(color & 0x2)
  338.       *(video_buffer+1) |= on_mask;
  339.  
  340.    end_line = (int *)((int *)_ytable[y] + ((x2 >> 3) & 0xfffe));
  341.  
  342.    on_mask = 0xFFFF >> (x2 & 0xf);
  343.    off_mask = ~on_mask;
  344.    
  345.    *(end_line) &= on_mask;
  346.    *(end_line+1) &= on_mask;
  347.    
  348.    if(color & 0x1)
  349.       *end_line |=  off_mask;
  350.  
  351.    if(color & 0x2)
  352.       *(end_line+1) |=  off_mask;
  353.  
  354.    on_mask = 0xffff;
  355.    loff_mask = 0x0L;
  356.    
  357.    for(index = 0; index < b_index; index++) {
  358.       video_buffer += 2;
  359.       *((long *)video_buffer) &= loff_mask;
  360.       if(color & 0x1) *video_buffer     |= on_mask;
  361.       if(color & 0x2) *(video_buffer+1) |= on_mask;
  362.    }
  363. }
  364.  
  365. /****************************************************************/
  366. /* Draw a line x1,y1,x2,y2,color                                */
  367. /****************************************************************/
  368. void draw_hline4(int x1, int x2, int y, int color)
  369. {
  370.    register int *video_buffer;
  371.    register int *end_line;
  372.    register int on_mask;
  373.    register int off_mask;
  374.    register int loff_mask;
  375.    register int index;
  376.    register int b_index;
  377.    
  378.    if(x1 < 0) x1 = 0;
  379.    if(x1 > _max_x) x1 = _max_x;
  380.    
  381.    if(x2 < 0) x2 = 0;
  382.    if(x2 > _max_x) x2 = _max_x;
  383.    
  384.    if(y > _max_y)   y = _max_y;
  385.    if(y < 0)   y = 0;
  386.       
  387.    if(x1 > x2) {
  388.       b_index = x1;
  389.       x1 = x2;
  390.       x2 = b_index;
  391.    }
  392.  
  393.    b_index = (x2 >> 4) - (x1 >> 4) - 1;
  394.    if(b_index < 1) {
  395.       (*d_line)(x1, y, x2, y, color);
  396.       return;
  397.    }
  398.    
  399.    video_buffer = (int *)((int *)_ytable[y] + ((x1 >> 2) & 0xfffc));
  400.  
  401.    on_mask = 0xFFFF >> (x1 & 0xf);
  402.    off_mask = ~on_mask;
  403.    
  404.    *(video_buffer)   &= off_mask;
  405.    *(video_buffer+1) &= off_mask;
  406.    *(video_buffer+2) &= off_mask;
  407.    *(video_buffer+3) &= off_mask;
  408.    
  409.    if(color & 0x1) *video_buffer     |= on_mask;
  410.    if(color & 0x2) *(video_buffer+1) |= on_mask;
  411.    if(color & 0x4) *(video_buffer+2) |= on_mask;
  412.    if(color & 0x8) *(video_buffer+3) |= on_mask;
  413.  
  414.    end_line = (int *)((int *)_ytable[y] + ((x2 >> 2) & 0xfffc));
  415.  
  416.    on_mask = 0xFFFF >> (x2 & 0xf);
  417.    off_mask = ~on_mask;
  418.  
  419.    *(end_line)   &= on_mask;
  420.    *(end_line+1) &= on_mask;
  421.    *(end_line+2) &= on_mask;
  422.    *(end_line+3) &= on_mask;
  423.    
  424.    if(color & 0x1) *end_line     |= off_mask;   
  425.    if(color & 0x2) *(end_line+1) |= off_mask;
  426.    if(color & 0x4) *(end_line+2) |= off_mask;
  427.    if(color & 0x8) *(end_line+3) |= off_mask;
  428.  
  429.    on_mask = 0xfffff;
  430.    loff_mask = 0x0L;
  431.    
  432.    for(index = 0; index < b_index; index++) {
  433.       video_buffer += 4;
  434.       *((long *)video_buffer)   &= loff_mask;
  435.       *((long *)video_buffer+1) &= loff_mask;
  436.  
  437.       if(color & 0x1) *video_buffer     |= on_mask;
  438.       if(color & 0x2) *(video_buffer+1) |= on_mask;
  439.       if(color & 0x4) *(video_buffer+2) |= on_mask;
  440.       if(color & 0x8) *(video_buffer+3) |= on_mask;
  441.    }
  442. }
  443.  
  444. /****************************************************************/
  445. /* Draw a line x1,y1,x2,y2,color                                */
  446. /****************************************************************/
  447. void draw_hline8(int x1, int x2, int y, int color)
  448. {
  449.    register int  *video_buffer;
  450.    register int  *end_line;
  451.    register int  on_mask;
  452.    register int  off_mask;
  453.    register int  loff_mask;
  454.    register int  index;
  455.    register int  b_index;
  456.    
  457.    if(x1 < 0) x1 = 0;
  458.    if(x1 > _max_x) x1 = _max_x;
  459.    
  460.    if(x2 < 0) x2 = 0;
  461.    if(x2 > _max_x) x2 = _max_x;
  462.    
  463.    if(y > _max_y)   y = _max_y;
  464.    if(y < 0)   y = 0;
  465.       
  466.    if(x1 > x2) {
  467.       b_index = x1;
  468.       x1 = x2;
  469.       x2 = b_index;
  470.    }
  471.  
  472.    b_index = (x2 >> 4) - (x1 >> 4) - 1;
  473.    if(b_index < 1) {
  474.       (*d_line)(x1, y, x2, y, color);
  475.       return;
  476.    }
  477.    
  478.    video_buffer = (int *)((int *)_ytable[y] + ((x1 >> 1) & 0xfff8));
  479.  
  480.    on_mask = 0xFFFF >> (x1 & 0xf);
  481.    off_mask = ~on_mask;
  482.    
  483.    *(video_buffer)   &= off_mask;
  484.    *(video_buffer+1) &= off_mask;
  485.    *(video_buffer+2) &= off_mask;
  486.    *(video_buffer+3) &= off_mask;
  487.    *(video_buffer+4) &= off_mask;
  488.    *(video_buffer+5) &= off_mask;
  489.    *(video_buffer+6) &= off_mask;
  490.    *(video_buffer+7) &= off_mask;
  491.    
  492.    if(color & 0x1)  *video_buffer     |= on_mask;
  493.    if(color & 0x2)  *(video_buffer+1) |= on_mask;
  494.    if(color & 0x4)  *(video_buffer+2) |= on_mask;
  495.    if(color & 0x8)  *(video_buffer+3) |= on_mask;
  496.    if(color & 0x10) *(video_buffer+4) |= on_mask;
  497.    if(color & 0x20) *(video_buffer+5) |= on_mask;
  498.    if(color & 0x40) *(video_buffer+6) |= on_mask;
  499.    if(color & 0x80) *(video_buffer+7) |= on_mask;
  500.  
  501.    end_line = (int *)((int *)_ytable[y] + ((x2 >> 1) & 0xfff8));
  502.  
  503.    on_mask = 0xFFFF >> (x2 & 0xf);
  504.    off_mask = ~on_mask;
  505.  
  506.    *(end_line)   &= on_mask;
  507.    *(end_line+1) &= on_mask;
  508.    *(end_line+2) &= on_mask;
  509.    *(end_line+3) &= on_mask;
  510.    *(end_line+4) &= on_mask;
  511.    *(end_line+5) &= on_mask;
  512.    *(end_line+6) &= on_mask;
  513.    *(end_line+7) &= on_mask;
  514.    
  515.    if(color & 0x1)  *end_line     |= off_mask;   
  516.    if(color & 0x2)  *(end_line+1) |= off_mask;
  517.    if(color & 0x4)  *(end_line+2) |= off_mask;
  518.    if(color & 0x8)  *(end_line+3) |= off_mask;
  519.    if(color & 0x10) *(end_line+4) |= off_mask;
  520.    if(color & 0x20) *(end_line+5) |= off_mask;
  521.    if(color & 0x40) *(end_line+6) |= off_mask;
  522.    if(color & 0x80) *(end_line+7) |= off_mask;
  523.  
  524.    on_mask = 0xfffff;
  525.    loff_mask = 0x0L;
  526.    
  527.    for(index = 0; index < b_index; index++) {
  528.       video_buffer += 8;
  529.       
  530.       *((long *)video_buffer)   &= loff_mask;
  531.       *((long *)video_buffer+1) &= loff_mask;
  532.       *((long *)video_buffer+2) &= loff_mask;
  533.       *((long *)video_buffer+3) &= loff_mask;
  534.  
  535.       if(color & 0x1)  *video_buffer     |= on_mask;
  536.       if(color & 0x2)  *(video_buffer+1) |= on_mask;
  537.       if(color & 0x4)  *(video_buffer+2) |= on_mask;
  538.       if(color & 0x8)  *(video_buffer+3) |= on_mask;
  539.       if(color & 0x10) *(video_buffer+4) |= on_mask;
  540.       if(color & 0x20) *(video_buffer+5) |= on_mask;
  541.       if(color & 0x40) *(video_buffer+6) |= on_mask;
  542.       if(color & 0x80) *(video_buffer+7) |= on_mask;
  543.    }
  544. }
  545.  
  546. /****************************************************************/
  547. /* Draw a line x1,y1,x2,y2,color                                */
  548. /****************************************************************/
  549. void draw_hline16(int x1, int x2, int y, int color)
  550. {
  551.    register int *video_buffer;
  552.    register int b_index;
  553.    register int index;
  554.    
  555.    if(x1 < 0) x1 = 0;
  556.    if(x1 > _max_x) x1 = _max_x;
  557.    
  558.    if(x2 < 0) x2 = 0;
  559.    if(x2 > _max_x) x2 = _max_x;
  560.    
  561.    if(y > _max_y)   y = _max_y;
  562.    if(y < 0)   y = 0;
  563.       
  564.    if(x1 > x2) {
  565.       b_index = x1;
  566.       x1 = x2;
  567.       x2 = b_index;
  568.    }
  569.    
  570.    b_index = x2 - x1;
  571.  
  572.    video_buffer = ((int *) _ytable[y]) + x1;
  573.    for(index = 0; index < b_index; index++)
  574.       *video_buffer++ = color;
  575. }
  576.  
  577. /****************************************************************/
  578. /* Draw a line x1,y1,x2,y2,color                                */
  579. /****************************************************************/
  580. void draw_line1(int x1, int y1, int x2, int y2, int color)
  581. {
  582.  
  583.    #define sign(x) ((x) > 0 ? 1: ((x) == 0 ? 0: (-1)))
  584.  
  585.    register int x, y, py, px;
  586.    register int dx,dy,dxabs,dyabs,i,sdx,sdy;
  587.    register char *video_buffer;
  588.    register char on_mask;
  589.    register char off_mask;
  590.  
  591.    if(x1 < 1) x1 = 0;
  592.    if(x1 > _max_x) x1 = _max_x;
  593.    if(x2 < 1) x2 = 0;
  594.    if(x2 > _max_x) x2 = _max_x;
  595.    if(y1 > _max_y) y1 = _max_y;
  596.    if(y1 < 1) y1 = 0;
  597.    if(y2 > _max_y) y2 = _max_y;
  598.    if(y2 < 1) y2 = 0;
  599.       
  600.    dx = x2 - x1;
  601.    dy = y2 - y1;
  602.  
  603.    sdx = sign(dx);
  604.    sdy = sign(dy);
  605.    dxabs = abs(dx);
  606.    dyabs = abs(dy);
  607.    x = 0;
  608.    y = 0;
  609.    px = x1;
  610.    py = y1;
  611.    
  612.    if(dxabs >= dyabs)
  613.    {
  614.       for(i = 0; i <= dxabs; i++)
  615.       {
  616.          y += dyabs;
  617.          
  618.          if(y >= dxabs)
  619.          {
  620.             y -= dxabs;
  621.             py += sdy;
  622.          }
  623.          
  624.          video_buffer = (char *)(_ytable[py] + (px >> 3));
  625.          on_mask = 0x80;
  626.          on_mask >>= (px & 0x7);
  627.          off_mask = ~on_mask;
  628.          *video_buffer &= off_mask;
  629.          if(color & 0x1)
  630.             *video_buffer |= on_mask;
  631.  
  632.          px += sdx;
  633.       }
  634.    }
  635.    else
  636.    {
  637.       for(i = 0; i < dyabs; i++)
  638.       {
  639.          x += dxabs;
  640.          if(x >= dyabs)
  641.          {
  642.             x -= dyabs;
  643.             px += sdx;
  644.          }
  645.  
  646.          video_buffer = (char *)(_ytable[py] + (px >> 3));
  647.          on_mask = 0x80;
  648.          on_mask >>= (px & 0x7);
  649.          off_mask = ~on_mask;
  650.          *video_buffer &= off_mask;
  651.          if(color & 0x1)
  652.             *video_buffer |= on_mask;
  653.  
  654.          py += sdy;
  655.       }
  656.    }
  657. }
  658.  
  659. /****************************************************************/
  660. /* Draw a line x1,y1,x2,y2,color                                */
  661. /****************************************************************/
  662. void draw_line2(int x1, int y1, int x2, int y2, int color)
  663. {
  664.  
  665.    #define sign(x) ((x) > 0 ? 1: ((x) == 0 ? 0: (-1)))
  666.  
  667.    register int x, y, py, px;
  668.    register int dx,dy,dxabs,dyabs,i,sdx,sdy;
  669.    register int *video_buffer;
  670.    register int on_mask;
  671.    register long off_mask;
  672.  
  673.    if(x1 < 1) x1 = 0;
  674.    if(x1 > _max_x) x1 = _max_x;
  675.    if(x2 < 1) x2 = 0;
  676.    if(x2 > _max_x) x2 = _max_x;
  677.    if(y1 > _max_y) y1 = _max_y;
  678.    if(y1 < 1) y1 = 0;
  679.    if(y2 > _max_y) y2 = _max_y;
  680.    if(y2 < 1) y2 = 0;
  681.       
  682.    dx = x2 - x1;
  683.    dy = y2 - y1;
  684.  
  685.    sdx = sign(dx);
  686.    sdy = sign(dy);
  687.    dxabs = abs(dx);
  688.    dyabs = abs(dy);
  689.    x = 0;
  690.    y = 0;
  691.    px = x1;
  692.    py = y1;
  693.    
  694.    if(dxabs >= dyabs)
  695.    {
  696.       for(i = 0; i <= dxabs; i++)
  697.       {
  698.          y += dyabs;
  699.          
  700.          if(y >= dxabs)
  701.          {
  702.             y -= dxabs;
  703.             py += sdy;
  704.          }
  705.          
  706.          off_mask = ~(0x80008000L >> (px & 0xf));
  707.          on_mask = 0x8000 >> (px & 0xf);
  708.    
  709.          video_buffer = (int *)((int *)_ytable[py] + ((px >> 3) & 0xfffe));
  710.          *((long *)video_buffer) &= off_mask;
  711.   
  712.          if(color & 0x1)
  713.             *video_buffer |= on_mask;
  714.          video_buffer++;
  715.          
  716.          if(color & 0x2)
  717.             *video_buffer |= on_mask;
  718.  
  719.          px += sdx;
  720.       }
  721.    }
  722.    else
  723.    {
  724.       for(i = 0; i < dyabs; i++)
  725.       {
  726.          x += dxabs;
  727.          if(x >= dyabs)
  728.          {
  729.             x -= dyabs;
  730.             px += sdx;
  731.          }
  732.  
  733.          off_mask = ~(0x80008000L >> (px & 0xf));
  734.          on_mask = 0x8000 >> (px & 0xf);
  735.    
  736.          video_buffer = (int *)((int *)_ytable[py] + ((px >> 3) & 0xfffe));
  737.          *((long *)video_buffer) &= off_mask;
  738.   
  739.          if(color & 0x1)
  740.             *video_buffer |= on_mask;
  741.          video_buffer++;
  742.          
  743.          if(color & 0x2)
  744.             *video_buffer |= on_mask;
  745.  
  746.          py += sdy;
  747.       }
  748.    }
  749. }
  750.  
  751. /****************************************************************/
  752. /* Draw a line x1,y1,x2,y2,color                                */
  753. /****************************************************************/
  754. void draw_line4(int x1, int y1, int x2, int y2, int color)
  755. {
  756.  
  757.    #define sign(x) ((x) > 0 ? 1: ((x) == 0 ? 0: (-1)))
  758.  
  759.    register int x, y, py, px;
  760.    register int dx,dy,dxabs,dyabs,i,sdx,sdy;
  761.    register int *video_buffer;
  762.    register int on_mask;
  763.    register long off_mask;
  764.  
  765.    if(x1 < 1) x1 = 0;
  766.    if(x1 > _max_x) x1 = _max_x;
  767.    if(x2 < 1) x2 = 0; 
  768.    if(x2 > _max_x) x2 = _max_x;
  769.    if(y1 > _max_y) y1 = _max_y;
  770.    if(y1 < 1) y1 = 0;
  771.    if(y2 > _max_y) y2 = _max_y;
  772.    if(y2 < 1) y2 = 0;
  773.       
  774.    dx = x2 - x1;
  775.    dy = y2 - y1;
  776.    
  777.    sdx = sign(dx);
  778.    sdy = sign(dy);
  779.    dxabs = abs(dx);
  780.    dyabs = abs(dy);
  781.  
  782.    x = 0;
  783.    y = 0;
  784.    px = x1;
  785.    py = y1;
  786.    
  787.    if(dxabs >= dyabs)
  788.    {
  789.       for(i = 0; i <= dxabs; i++)
  790.       {
  791.          y += dyabs;
  792.          
  793.          if(y >= dxabs)
  794.          {
  795.             y -= dxabs;
  796.             py += sdy;
  797.          }
  798.          
  799.          off_mask = ~(0x80008000L >> (px & 0xf));
  800.          on_mask = 0x8000 >> (px & 0xf);
  801.    
  802.          video_buffer = (int *)((int *)_ytable[py] + ((px >> 2) & 0xfffc));
  803.  
  804.          *((long *)video_buffer) &= off_mask;
  805.          *((long *)video_buffer+1) &= off_mask;
  806.    
  807.          if(color & 0x1)
  808.             *video_buffer |= on_mask;
  809.          video_buffer++;
  810.  
  811.          if(color & 0x2)
  812.             *video_buffer |= on_mask;
  813.          video_buffer++;
  814.  
  815.          if(color & 0x4)
  816.             *video_buffer |= on_mask;
  817.          video_buffer++;
  818.  
  819.          if(color & 0x8)
  820.             *video_buffer |= on_mask;
  821.  
  822.          px += sdx;
  823.       }
  824.    }
  825.    else
  826.    {
  827.       for(i = 0; i < dyabs; i++)
  828.       {
  829.          x += dxabs;
  830.          if(x >= dyabs)
  831.          {
  832.             x -= dyabs;
  833.             px += sdx;
  834.          }
  835.  
  836.          off_mask = ~(0x80008000L >> (px & 0xf));
  837.          on_mask = 0x8000 >> (px & 0xf);
  838.    
  839.          video_buffer = (int *)((int *)_ytable[py] + ((px >> 2) & 0xfffc));
  840.  
  841.          *((long *)video_buffer) &= off_mask;
  842.          *((long *)video_buffer+1) &= off_mask;
  843.    
  844.          if(color & 0x1)
  845.             *video_buffer |= on_mask;
  846.          video_buffer++;
  847.  
  848.          if(color & 0x2)
  849.             *video_buffer |= on_mask;
  850.          video_buffer++;
  851.  
  852.          if(color & 0x4)
  853.             *video_buffer |= on_mask;
  854.          video_buffer++;
  855.  
  856.          if(color & 0x8)
  857.             *video_buffer |= on_mask;
  858.  
  859.          py += sdy;
  860.       }
  861.    }
  862. }
  863. /****************************************************************/
  864. /* Draw a line x1,y1,x2,y2,color                                */
  865. /****************************************************************/
  866. void draw_line8(int x1, int y1, int x2, int y2, int color)
  867. {
  868.  
  869.    #define sign(x) ((x) > 0 ? 1: ((x) == 0 ? 0: (-1)))
  870.  
  871.    register int x, y, py, px;
  872.    register int dx,dy,dxabs,dyabs,i,sdx,sdy;
  873.    register int *video_buffer;
  874.    register int on_mask;
  875.    register long off_mask;
  876.  
  877.    if(x1 < 1) x1 = 0;
  878.    if(x1 > _max_x) x1 = _max_x;
  879.    if(x2 < 1) x2 = 0;
  880.    if(x2 > _max_x) x2 = _max_x;
  881.    if(y1 > _max_y) y1 = _max_y;
  882.    if(y1 < 1) y1 = 0;
  883.    if(y2 > _max_y) y2 = _max_y;
  884.    if(y2 < 1) y2 = 0;
  885.       
  886.    dx = x2 - x1;
  887.    dy = y2 - y1;
  888.  
  889.    sdx = sign(dx);
  890.    sdy = sign(dy);
  891.    dxabs = abs(dx);
  892.    dyabs = abs(dy);
  893.    x = 0;
  894.    y = 0;
  895.    px = x1;
  896.    py = y1;
  897.    
  898.    if(dxabs >= dyabs)
  899.    {
  900.       for(i = 0; i <= dxabs; i++)
  901.       {
  902.          y += dyabs;
  903.          
  904.          if(y >= dxabs)
  905.          {
  906.             y -= dxabs;
  907.             py += sdy;
  908.          }
  909.  
  910.          off_mask = ~(0x80008000L >> (px & 0xf));
  911.          on_mask = 0x8000 >> (px & 0xf);
  912.    
  913.          video_buffer = (int *)((int *)_ytable[py] + ((px >> 1) & 0xfff8));
  914.  
  915.          *((long *)video_buffer)   &= off_mask;
  916.          *((long *)video_buffer+1) &= off_mask;
  917.          *((long *)video_buffer+2) &= off_mask;
  918.          *((long *)video_buffer+3) &= off_mask;
  919.    
  920.          if(color & 0x1)
  921.             *video_buffer |= on_mask;
  922.          video_buffer++;
  923.  
  924.          if(color & 0x2)
  925.             *video_buffer |= on_mask;
  926.          video_buffer++;
  927.  
  928.          if(color & 0x4)
  929.             *video_buffer |= on_mask;
  930.          video_buffer++;
  931.  
  932.          if(color & 0x8)
  933.             *video_buffer |= on_mask;
  934.          video_buffer++;
  935.    
  936.          if(color & 0x10)
  937.             *video_buffer |= on_mask;
  938.          video_buffer++;
  939.  
  940.          if(color & 0x20)
  941.             *video_buffer |= on_mask;
  942.          video_buffer++;
  943.  
  944.          if(color & 0x40)
  945.             *video_buffer |= on_mask;
  946.          video_buffer++;
  947.  
  948.          if(color & 0x80)
  949.             *video_buffer |= on_mask;
  950.          
  951.          px += sdx;
  952.       }
  953.    }
  954.    else
  955.    {
  956.       for(i = 0; i < dyabs; i++)
  957.       {
  958.          x += dxabs;
  959.          if(x >= dyabs)
  960.          {
  961.             x -= dyabs;
  962.             px += sdx;
  963.          }
  964.  
  965.          off_mask = ~(0x80008000L >> (px & 0xf));
  966.          on_mask = 0x8000 >> (px & 0xf);
  967.    
  968.          video_buffer = (int *)((int *)_ytable[py] + ((px >> 1) & 0xfff8));
  969.  
  970.          *((long *)video_buffer)   &= off_mask;
  971.          *((long *)video_buffer+1) &= off_mask;
  972.          *((long *)video_buffer+2) &= off_mask;
  973.          *((long *)video_buffer+3) &= off_mask;
  974.    
  975.          if(color & 0x1)
  976.             *video_buffer |= on_mask;
  977.          video_buffer++;
  978.  
  979.          if(color & 0x2)
  980.             *video_buffer |= on_mask;
  981.          video_buffer++;
  982.  
  983.          if(color & 0x4)
  984.             *video_buffer |= on_mask;
  985.          video_buffer++;
  986.  
  987.          if(color & 0x8)
  988.             *video_buffer |= on_mask;
  989.          video_buffer++;
  990.    
  991.          if(color & 0x10)
  992.             *video_buffer |= on_mask;
  993.          video_buffer++;
  994.  
  995.          if(color & 0x20)
  996.             *video_buffer |= on_mask;
  997.          video_buffer++;
  998.  
  999.          if(color & 0x40)
  1000.             *video_buffer |= on_mask;
  1001.          video_buffer++;
  1002.  
  1003.          if(color & 0x80)
  1004.             *video_buffer |= on_mask;
  1005.          
  1006.          py += sdy;
  1007.       }
  1008.    }
  1009. }
  1010.  
  1011. /****************************************************************/
  1012. /* Draw a line x1,y1,x2,y2,color                                */
  1013. /****************************************************************/
  1014. void draw_line16(int x1, int y1, int x2, int y2, int color)
  1015. {
  1016.  
  1017.    #define sign(x) ((x) > 0 ? 1: ((x) == 0 ? 0: (-1)))
  1018.  
  1019.    register int x, y, py, px;
  1020.    register int dx,dy,dxabs,dyabs,i,sdx,sdy;
  1021.    register int *video_buffer;
  1022.    register int on_mask;
  1023.    register long off_mask;
  1024.  
  1025.    if(x1 < 1) x1 = 0;
  1026.    if(x1 > _max_x) x1 = _max_x;
  1027.    if(x2 < 1) x2 = 0;
  1028.    if(x2 > _max_x) x2 = _max_x;
  1029.    if(y1 > _max_y) y1 = _max_y;
  1030.    if(y1 < 1) y1 = 0;
  1031.    if(y2 > _max_y) y2 = _max_y;
  1032.    if(y2 < 1) y2 = 0;
  1033.       
  1034.    dx = x2 - x1;
  1035.    dy = y2 - y1;
  1036.  
  1037.    sdx = sign(dx);
  1038.    sdy = sign(dy);
  1039.    dxabs = abs(dx);
  1040.    dyabs = abs(dy);
  1041.    x = 0;
  1042.    y = 0;
  1043.    px = x1;
  1044.    py = y1;
  1045.    
  1046.    if(dxabs >= dyabs)
  1047.    {
  1048.       for(i = 0; i <= dxabs; i++)
  1049.       {
  1050.          y += dyabs;
  1051.          
  1052.          if(y >= dxabs)
  1053.          {
  1054.             y -= dxabs;
  1055.             py += sdy;
  1056.          }
  1057.          
  1058.          *(unsigned int *) (((int *)_ytable[py]) + (px)) = color;
  1059.          px += sdx;
  1060.       }
  1061.    }
  1062.    else
  1063.    {
  1064.       for(i = 0; i < dyabs; i++)
  1065.       {
  1066.          x += dxabs;
  1067.          if(x >= dyabs)
  1068.          {
  1069.             x -= dyabs;
  1070.             px += sdx;
  1071.          }
  1072.  
  1073.          *(unsigned int *) (((int *)_ytable[py]) + (px)) = color;
  1074.  
  1075.          py += sdy;
  1076.       }
  1077.    }
  1078. }
  1079.  
  1080. /*************************************************************/
  1081. pinit(int max_x, int max_y, void *video_buffer, int planes)
  1082. {
  1083.    int offset = 0;
  1084.    int index = 0;
  1085.    int i = 0;
  1086.    long tempcount = 0;
  1087.    char *temp;
  1088.    float ftemp;
  1089.    static char *errmsg = "Graphics Memory Allocation Error!";
  1090.  
  1091.    _max_x = max_x-1;
  1092.    _max_y = max_y-1;
  1093.    
  1094.    if(Malloc(-1) < sizeof(long) * max_y) {
  1095.       fprintf(stderr,"%s\n",errmsg);
  1096.       return(-1);
  1097.    }
  1098.    _ytable = Malloc((long)sizeof(long) * (long)max_y);
  1099.    
  1100.    temp = (char *)video_buffer;
  1101.    
  1102.    /* Get the number of byte per X row. */
  1103.    offset = (max_x / 8) * planes;
  1104.    
  1105.    /* Build the Y vector table.         */
  1106.    for(index = 0; index < max_y; index++)  {
  1107.       *(_ytable+index) = temp;
  1108.       temp += offset;
  1109.    }
  1110.    
  1111.    /* Calulate screen aspect ratio for circle drawing routine. */
  1112.    
  1113.    if(_monitor_aspect == 0.0) _monitor_aspect = 0.75;
  1114.    
  1115.    ftemp = ((float) max_y) / ((float) max_x) / _monitor_aspect;
  1116.  
  1117.    if(ftemp < 0.0) ftemp = -ftemp;
  1118.  
  1119.    _aspect = 0;
  1120.    
  1121.    if(ftemp != 1.0) {
  1122.       tempcount = (long) sizeof(long) * (long) (max_x*2) * 2;
  1123.       tempcount += sizeof(long) * 2;
  1124.          
  1125.       if(Malloc(-1) < tempcount) {
  1126.          fprintf(stderr,"%s\n",errmsg);
  1127.          return(-1);
  1128.       }
  1129.       
  1130.       _scaleptr = Malloc(tempcount);
  1131.       
  1132.      if(max_y > max_x)
  1133.          ftemp = ((float) max_x) / ((float) max_y) / (1 / _monitor_aspect);   
  1134.  
  1135.       _aspect = 1;
  1136.       i = 0;
  1137.       for(index = -max_x; index <= max_x; index++) {
  1138.          *(_scaleptr+i) = (long)(((long) index) * ftemp);
  1139.          i++;
  1140.          if(index == 0) _scale = _scaleptr+i;
  1141.       }
  1142.    }
  1143.      
  1144.    switch(planes)
  1145.    {
  1146.       default: p_pixel = set_pixel1;
  1147.                d_line = draw_line1;
  1148.                d_hline = draw_hline1;
  1149.                g_pixel = get_pixel1;
  1150.                byte2raw = byte2raw1;
  1151.                color_shift = 7;
  1152.                break;
  1153.       case 2:  p_pixel = set_pixel2;
  1154.                d_line = draw_line2;
  1155.                d_hline = draw_hline2;
  1156.                g_pixel = get_pixel2;
  1157.                byte2raw = byte2raw2;
  1158.                color_shift = 6;
  1159.                break;
  1160.       case 4:  p_pixel = set_pixel4;
  1161.                d_line = draw_line4;
  1162.                d_hline = draw_hline4;
  1163.                g_pixel = get_pixel4;
  1164.                byte2raw = byte2raw4;
  1165.                color_shift = 4;
  1166.                break;
  1167.       case 8:  p_pixel = set_pixel8;
  1168.                d_line = draw_line8;
  1169.                d_hline = draw_hline8;
  1170.                g_pixel = get_pixel8;
  1171.                byte2raw = byte2raw8;
  1172.                color_shift = 0;
  1173.                break;
  1174.       case 16: p_pixel = set_pixel16;
  1175.                d_line = draw_line16;
  1176.                d_hline = draw_hline16;
  1177.                g_pixel = get_pixel16;
  1178.                byte2raw = byte2raw8;
  1179.                color_shift = 0;
  1180.                break;
  1181.    }
  1182. }
  1183.  
  1184. /*************************************************************/
  1185. void pexit()
  1186. {
  1187.    Mfree(_ytable);
  1188.    Mfree(_scaleptr);
  1189. }
  1190.  
  1191. /*************************************************************/
  1192. set_pixel1(register int x, register int y, int color)
  1193. {
  1194.    register int xx;
  1195.    register unsigned char *video_buffer;
  1196.    register unsigned char on_mask;
  1197.    register unsigned char off_mask;
  1198.  
  1199.    if(x < 0 || x > _max_x) return;
  1200.    if(y < 0 || y > _max_y) return;
  1201.    
  1202.    xx = x >> 3;
  1203.    x &= 0x7;
  1204.    video_buffer = (char *)(_ytable[y] + xx);
  1205.    on_mask = 0x80;
  1206.    on_mask >>= x;
  1207.    off_mask = ~on_mask;
  1208.    *video_buffer &= off_mask;
  1209.    if(color & 0x1)
  1210.      *video_buffer |= on_mask;
  1211. }
  1212. /*************************************************************/
  1213. set_pixel2(register int x, register int y, int color)
  1214. {
  1215.    register int xx;
  1216.    register int *video_buffer;
  1217.    register int on_mask;
  1218.    register long off_mask;
  1219.    
  1220.    if(x < 0 || x > _max_x) return;
  1221.    if(y < 0 || y > _max_y) return;
  1222.    
  1223.    xx = (x >> 4);
  1224.    xx <<= 1;
  1225.    x &= 0xf;
  1226.    off_mask = ~(0x80008000L >> x);
  1227.    on_mask = 0x8000 >> x;
  1228.    
  1229.    video_buffer = (int *)((int *)_ytable[y] + xx);
  1230.    *((long *)video_buffer) &= off_mask;
  1231.   
  1232.    if(color & 0x1)
  1233.      *video_buffer |= on_mask;
  1234.    video_buffer++;
  1235.    if(color & 0x2)
  1236.      *video_buffer |= on_mask;
  1237. }
  1238. /*************************************************************/
  1239. set_pixel4(register int x, register int y, int color)
  1240. {
  1241.    register int xx;
  1242.    register int *video_buffer;
  1243.    register int on_mask;
  1244.    register long off_mask;
  1245.    
  1246.    if(x < 0 || x > _max_x) return;
  1247.    if(y < 0 || y > _max_y) return;
  1248.    
  1249.    xx = (x >> 4);
  1250.    xx <<= 2;
  1251.    x &= 0xf;
  1252.    off_mask = ~(0x80008000L >> x);
  1253.    on_mask = 0x8000 >> x;
  1254.    
  1255.    video_buffer = (int *)((int *)_ytable[y] + xx);
  1256.  
  1257.    *((long *)video_buffer) &= off_mask;
  1258.    *((long *)video_buffer+1) &= off_mask;
  1259.    
  1260.    if(color & 0x1)
  1261.      *video_buffer |= on_mask;
  1262.    video_buffer++;
  1263.  
  1264.    if(color & 0x2)
  1265.      *video_buffer |= on_mask;
  1266.    video_buffer++;
  1267.  
  1268.    if(color & 0x4)
  1269.      *video_buffer |= on_mask;
  1270.    video_buffer++;
  1271.  
  1272.    if(color & 0x8)
  1273.      *video_buffer |= on_mask;
  1274.      
  1275. }
  1276. /*************************************************************/
  1277. set_pixel8(register int x, register int y, int color)
  1278. {
  1279.    register int xx;
  1280.    register int *video_buffer;
  1281.    register int on_mask;
  1282.    register long off_mask;
  1283.    
  1284.    if(x < 0 || x > _max_x) return;
  1285.    if(y < 0 || y > _max_y) return;
  1286.    
  1287.    xx = (x >> 4);
  1288.    xx <<= 3;
  1289.    x &= 0xf;
  1290.    off_mask = ~(0x80008000L >> x);
  1291.    on_mask = 0x8000 >> x;
  1292.    
  1293.    video_buffer = (int *)((int *)_ytable[y] + xx);
  1294.  
  1295.    *((long *)video_buffer)   &= off_mask;
  1296.    *((long *)video_buffer+1) &= off_mask;
  1297.    *((long *)video_buffer+2) &= off_mask;
  1298.    *((long *)video_buffer+3) &= off_mask;
  1299.    
  1300.    if(color & 0x1)
  1301.      *video_buffer |= on_mask;
  1302.    video_buffer++;
  1303.  
  1304.    if(color & 0x2)
  1305.      *video_buffer |= on_mask;
  1306.    video_buffer++;
  1307.  
  1308.    if(color & 0x4)
  1309.      *video_buffer |= on_mask;
  1310.    video_buffer++;
  1311.  
  1312.    if(color & 0x8)
  1313.      *video_buffer |= on_mask;
  1314.    video_buffer++;
  1315.    
  1316.    if(color & 0x10)
  1317.      *video_buffer |= on_mask;
  1318.    video_buffer++;
  1319.  
  1320.    if(color & 0x20)
  1321.      *video_buffer |= on_mask;
  1322.    video_buffer++;
  1323.  
  1324.    if(color & 0x40)
  1325.      *video_buffer |= on_mask;
  1326.    video_buffer++;
  1327.  
  1328.    if(color & 0x80)
  1329.      *video_buffer |= on_mask;
  1330.      
  1331. }
  1332. /*************************************************************/
  1333.  
  1334. set_pixel16(int x, int y, int color)
  1335. {   
  1336.    if(x < 0 || x > _max_x) return;
  1337.    if(y < 0 || y > _max_y) return;
  1338.  
  1339.    *(unsigned int *) (((int *)_ytable[y]) + (x)) = color;
  1340. }
  1341.  
  1342. /****************************************************************/
  1343. int get_pixel1(int x, int y)
  1344. {
  1345.    register int xx;
  1346.    register char *video_buffer;
  1347.    register char on_mask;
  1348.    register int color;
  1349.    
  1350.    if(x < 0 || x > _max_x) return(1);
  1351.    if(y < 0 || y > _max_y) return(1);
  1352.  
  1353.    xx = x >> 3;
  1354.    x &= 0x7;
  1355.    video_buffer = (char *)(_ytable[y] + xx);
  1356.    on_mask = 0x80;
  1357.    on_mask >>= x;
  1358.  
  1359.    color = 0;
  1360.    
  1361.    if(*video_buffer & on_mask) color |= 0x1;
  1362.  
  1363.    return(color);
  1364. }
  1365.  
  1366. /****************************************************************/
  1367. int get_pixel2(int x, int y)
  1368. {
  1369.    register int xx;
  1370.    register int *video_buffer;
  1371.    register int on_mask;
  1372.    register int color;
  1373.    
  1374.    if(x < 0 || x > _max_x) return(1);
  1375.    if(y < 0 || y > _max_y) return(1);
  1376.  
  1377.    xx = (x >> 4);
  1378.    xx <<= 1;
  1379.    x &= 0xf;
  1380.    on_mask = 0x8000 >> x;
  1381.    
  1382.    video_buffer = (int *)((int *)_ytable[y] + xx);
  1383.  
  1384.    color = 0;
  1385.    
  1386.    if(*video_buffer & on_mask) color |= 0x1;
  1387.    video_buffer++;
  1388.  
  1389.    if(*video_buffer & on_mask) color |= 0x2;
  1390.  
  1391.    return(color);
  1392. }
  1393.  
  1394.  
  1395. /****************************************************************/
  1396. int get_pixel4(int x, int y)
  1397. {
  1398.    register int xx;
  1399.    register int *video_buffer;
  1400.    register int on_mask;
  1401.    register int color;
  1402.  
  1403.    if(x < 0 || x > _max_x) return(1);
  1404.    if(y < 0 || y > _max_y) return(1);
  1405.       
  1406.    xx = (x >> 4);
  1407.    xx <<= 2;
  1408.    x &= 0xf;
  1409.    on_mask = 0x8000 >> x;
  1410.    
  1411.    video_buffer = (int *)((int *)_ytable[y] + xx);
  1412.  
  1413.    color = 0;
  1414.    
  1415.    if(*video_buffer & on_mask) color |= 0x1;
  1416.    video_buffer++;
  1417.  
  1418.    if(*video_buffer & on_mask) color |= 0x2;
  1419.    video_buffer++;
  1420.  
  1421.    if(*video_buffer & on_mask) color |= 0x4;
  1422.    video_buffer++;
  1423.  
  1424.    if(*video_buffer & on_mask) color |= 0x8;   
  1425.      
  1426.    return(color);
  1427. }
  1428.  
  1429. /****************************************************************/
  1430. int get_pixel8(int x, int y)
  1431. {
  1432.    register int xx;
  1433.    register int *video_buffer;
  1434.    register int on_mask;
  1435.    register int color;
  1436.       
  1437.    if(x < 0 || x > _max_x) return(1);
  1438.    if(y < 0 || y > _max_y) return(1);
  1439.  
  1440.    xx = (x >> 4);
  1441.    xx <<= 3;
  1442.    x &= 0xf;
  1443.    on_mask = 0x8000 >> x;
  1444.    
  1445.    video_buffer = (int *)((int *)_ytable[y] + xx);
  1446.  
  1447.    color = 0;
  1448.    
  1449.    if(*video_buffer & on_mask) color |= 0x1;
  1450.    video_buffer++;
  1451.  
  1452.    if(*video_buffer & on_mask) color |= 0x2;
  1453.    video_buffer++;
  1454.  
  1455.    if(*video_buffer & on_mask) color |= 0x4;
  1456.    video_buffer++;
  1457.  
  1458.    if(*video_buffer & on_mask) color |= 0x8;   
  1459.    video_buffer++;
  1460.    
  1461.    if(*video_buffer & on_mask) color |= 0x10;   
  1462.    video_buffer++;
  1463.  
  1464.    if(*video_buffer & on_mask) color |= 0x20;
  1465.    video_buffer++;
  1466.  
  1467.    if(*video_buffer & on_mask) color |= 0x40;
  1468.    video_buffer++;
  1469.  
  1470.    if(*video_buffer & on_mask) color |= 0x80;   
  1471.    video_buffer++;
  1472.      
  1473.    return(color);
  1474. }
  1475.  
  1476. /*************************************************************/
  1477.  
  1478. int get_pixel16(int x, int y)
  1479. {
  1480.    return(*(unsigned int *) (((int *)_ytable[y]) + (x)));
  1481. }
  1482.